home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / astrsys / fixup.asm < prev    next >
Assembly Source File  |  1989-09-25  |  11KB  |  227 lines

  1.                    PAGE    ,132
  2. ; ============== Turbo Prolog Interface ===================================
  3. ; The Purpose of these Clauses is to Fixup a name so that They look nice
  4. ; In turbo prolog..
  5. ; Note that the call is fixup(Instring,Outstring),
  6. ; Turbo Prolog Supplies us with the address of the Instring at [Bp+10] modif.
  7. ; The Outstring address we MUST supply to turbo prolog and this address MUST
  8. ; be placed at [Bp+6]modified .
  9. ; Note that the latest changes have made the algorithm so that the
  10. ; array of strings is now circular.
  11. ;
  12. ; Note that to use this for turbo prolog, you must declare this routine
  13. ; external asm in the GLOBAL PREDICATES SECTION, i.e.
  14. ;
  15. ; GLOBAL PREDICATES
  16. ;        .
  17. ;        .
  18. ;        .
  19. ; determ fixup(STRING,STRING) - (i,o) language asm
  20. ;
  21. ; A string Must be used as the parameter type.
  22.  
  23. .XLIST
  24. XchgSeg         MACRO   Seg1,Seg2
  25.                 Push    Seg1        ; Save the Segment register
  26.                 Push    Seg2        ; Save the Segment register
  27.                 Pop     Seg1        ; Put Segment here
  28.                 Pop     Seg2        ; The same for the first
  29.                 ENDM
  30.  
  31. Pusha           MACRO
  32.                 Push    Ax          ; Save the regs
  33.                 Push    Bx          ;
  34.                 Push    Cx          ;
  35.                 Push    Dx          ;
  36.                 Push    Bp          ;
  37.                 Push    Si          ;
  38.                 Push    Di          ;
  39.                 Pushf               ; And the fags
  40.                 ENDM
  41.  
  42. Popa            MACRO
  43.                 Popf                ; Pop All
  44.                 Pop     Di          ;
  45.                 Pop     Si          ;
  46.                 Pop     Bp          ;
  47.                 Pop     Dx          ;
  48.                 Pop     Cx          ;
  49.                 Pop     Bx          ;
  50.                 Pop     Ax          ;
  51.                 ENDM
  52.  
  53. .LIST
  54.  
  55.  
  56.                 Public  fixup_0
  57.  
  58. InputArg        Equ [Bp+10]
  59. OutputArg       Equ [Bp+6]
  60. BytesPerEntry   Equ 40
  61.  
  62.  
  63. Fixup           Segment Byte
  64.                 Assume  Cs:Fixup
  65.  
  66. DataArea        DB      40 dup(BytesPerEntry dup("*"))  ; A 40x40 array
  67. OldDs           Dw      ?
  68. OldEs           Dw      ?
  69. CurrPos         Db      0           ; Defines current position
  70. CurrOff         Dw      OFFSET DataArea ; This is what it starts at -- Changes
  71.  
  72.  
  73. fixup_0         Proc    Far
  74. ;-----------------------------------------------------------------------------;
  75. ; form is fixup(String,String) -- (i,o)                                       ;
  76. ;-----------------------------------------------------------------------------;
  77.                 Push    Bp                      ; Modified Bp, here!
  78.                 Mov     Bp,Sp                   ;
  79.                 Pusha                           ;
  80.                 Mov     OldDs,Ds                ;
  81.                 Mov     OldEs,Es                ;
  82.                 Lds     Si,InputArg             ;
  83.                 Push    Cs                      ; DatArea Segment is same as Cs
  84.                 Pop     Es                      ; To here
  85.                 Mov     Di,CurrOff              ; Snag the current offset
  86.                 Call    Proper                  ;
  87.                 Lds     Si,OutputArg            ; Place OUR ADDRESS HERE
  88.                 Mov     [Si+2],Es               ;
  89.                 Mov     [Si],Di                 ; Now Prolog knows where
  90.                 Inc     CurrPos                 ; Increment this
  91.                 Add     CurrOff,BytesPerEntry   ; Add to have new ofset next
  92.                 Mov     Ax,CurrOff              ; Get the current offset
  93.                 Mov     Bx,(SIZE DataArea)*BytesPerEntry; Get the # bytes there
  94.                 Cwd                             ; Do this
  95.                 Div     Bx                      ; Check it out
  96.                 Jo      NoCirculate             ; If OV then it's not past end
  97.                 Mov     Ax,OFFSET DataArea      ; Get the offset
  98.                 Mov     CurrOff,Ax              ; Save the first value
  99.                 Mov     CurrPos,0               ; And Clear this
  100. NoCirculate:    Mov     Ax,OldDs                ;
  101.                 Mov     Ds,Ax                   ;
  102.                 Mov     Ax,OldEs                ;
  103.                 Mov     Es,Ax                   ;
  104.                 Popa                            ;
  105.                 Pop     Bp                      ;
  106.                 Ret     8                       ; Retrun removing parms
  107. fixup_0         Endp
  108.  
  109.                                                 Page
  110. Length          Proc    Near
  111. ;-----------------------------------------------------------------------------;
  112. ;   Returns the length of an asciiz string.                                   ;
  113. ;   INPUT:                                                                    ;
  114. ;      DS:SI  = Address of ASCIIZ string                                      ;
  115. ;   OUTPUT:                                                                   ;
  116. ;      AX = Length of string (Not including the NULL char at end              ;
  117. ;-----------------------------------------------------------------------------;
  118.                 Push    Di          ;
  119.                 Push    Cx          ; Save them
  120.                                     ;
  121.                 Xor     Cx,Cx       ; Clear to 0
  122.                 Not     Cx          ; And flip the bits
  123.                 Cld                 ;
  124.                 Mov     Di,Si       ;
  125.                 XchgSeg Ds,Es       ;
  126.                                     ;
  127.                 Mov     Al,0        ; Search
  128.                 Repnz   Scasb       ; Scan for the 0
  129.                 Not     Cx          ; Flip the bits back
  130.                 Mov     Ax,Cx       ; Put count Here
  131.                 Dec     Ax          ; And take one out -- do not include 0
  132.                 XchgSeg Ds,Es       ;
  133.                                     ;
  134.                 Pop     Cx          ; Get the old Cx
  135.                 Pop     Di          ; Get the ols si
  136.                 Ret                 ; And exit
  137. Length          Endp
  138.  
  139.                                                 Page
  140. LowerCase       Proc    Near
  141. ;-----------------------------------------------------------------------------;
  142. ; Converts entire input string to lowercase.                                  ;
  143. ; INPUT :                                                                     ;
  144. ;    DS:SI = Address of source string.                                        ;
  145. ;    ES:DI = Address of new string exactly like first exept all lc.           ;
  146. ; OUTPUT :                                                                    ;
  147. ;    ES:DI = Address of New string all in lowercase.                          ;
  148. ;-----------------------------------------------------------------------------;
  149.                 Pusha               ;
  150.                 Cld                 ; Yep
  151.                                     ;
  152.                 Call    Length      ; Get the Length
  153.                 Mov     Cx,Ax       ; Put it for the count
  154. _UtoLtop:       Lodsb               ; Get it
  155.                 Cmp     Al,'A'      ; Well
  156.                 Jb      @F          ; Nope
  157.                 Cmp     Al,'Z'      ; Well...
  158.                 Ja      @F          ; Nope skip add
  159.                 Add     Al,20h      ; Convert to lower case
  160. @@:             Stosb               ;
  161.                 Loop    _UtoLtop    ; Back
  162.                                     ;
  163.                 Popa                ;
  164.                 Ret                 ;
  165. LowerCase       Endp
  166.  
  167.                                                 Page
  168. Proper          Proc    Near
  169. ;-----------------------------------------------------------------------------;
  170. ; Make a given input string to proper format. i. e.                           ;
  171. ;    "THIS IS A STRING",0     made proper would look like...                  ;
  172. ;    "This Is A String",0                                                     ;
  173. ; INPUT :                                                                     ;
  174. ;      DS:SI = Source input string.                                           ;
  175. ;      ES:DI = Destination address.                                           ;
  176. ; OUTPUT:                                                                     ;
  177. ;      ES:DI = address of output proper string.                               ;
  178. ;-----------------------------------------------------------------------------;
  179.                 Pusha               ;
  180.                 Cld                 ;
  181.                                     ; First convert to lowercase
  182.                 Mov     Di,Si       ; First make the source all lower
  183.                 Push    Es          ;
  184.                 Mov     Ax,Ds       ; Equate source and destination
  185.                 Mov     Es,Ax       ; so we can call below.
  186.                 Call    LowerCase   ; Make it all like lower case
  187.                                     ; Now search and do.
  188.                 Pop     Es          ;
  189.                 Popa                ;
  190.                 Pusha               ;
  191.                 Mov     Ah,0        ; Clear our flag
  192. _FindWord:      Lodsb               ;
  193.                 Cmp     Al,0        ; Are we done
  194.                 Je      _ProperDone ;
  195.                 Cmp     Al,'a'      ; well?
  196.                 Jb      @F          ;
  197.                 Cmp     Al,'z'      ;
  198.                 Ja      @F          ;
  199.                 Add     Al,-20h     ; Ok
  200.                 Dec     Ah          ;
  201. @@:             Stosb               ;
  202.                 Or      Ah,Ah       ;
  203.                 Jns     _FindWord   ; Not negative then keep finding
  204.                                     ; Found word and converted
  205. _FindDelim:     Lodsb               ; Grab
  206.                 Cmp     Al,0        ;
  207.                 Je      _ProperDone ;
  208.                 Cmp     Al,'a'      ; Well
  209.                 Jae     _Pt2xx      ;
  210.                 Jmp     SHORT   _DFp;
  211. _Pt2xx:         Cmp     Al,'z'      ; Ok?
  212.                 Jbe     @F          ; Skip the flag reset
  213. _DFp:           Inc     Ah          ; Back to 0
  214. @@:             Stosb               ;
  215.                 Or      Ah,Ah       ;
  216.                 Js      _FindDelim  ; While negative keep searching
  217.                 Jmp     _FindWord   ; Back to word search
  218. _ProperDone:    Stosb               ; Save the ASCIIZ
  219.                                     ;
  220.                 Popa                ;
  221.                 Ret                 ;
  222. Proper          Endp
  223.  
  224.  
  225. Fixup           Ends
  226.                 END
  227.